<?php 
$colname_rs_up = "-1";
if (isset($_GET['itemid'])) {
    $colname_rs_up = $_GET['itemid'];
}

$rs_up = getContentDetails($colname_rs_up);
$row_rs_up = mysql_fetch_assoc($rs_up);
$totalRows_rs_up = mysql_num_rows($rs_up);

$colname_rs_resources = "-1";
if (isset($_GET['itemid'])) {
    $colname_rs_resources = $_GET['itemid'];
}
$rs_resources =getContentResource($colname_rs_resources);
$row_rs_resources = mysql_fetch_assoc($rs_resources);
$totalRows_rs_resources = mysql_num_rows($rs_resources);

$cat = $row_rs_up['category_id'];
if(strlen($cat)<1)
    $cat=0;
?>
<?php if($row_rs_up["category_type"]=="cat") { ?>
<ul id="contentCategory" class="shadetabs" style="margin-top: 5px;">
    <li><a href="#" rel="tabcontentM">Content</a></li>
    <li><a href="#" rel="tabcategory">Category</a></li>
</ul>
<div class="allround" style="margin-left: 2px;margin-right: 5px">
    <div id="tabcontentM" class="tabcontent">
            <?php } $addUrl = "?page=".$_GET["page"];
            if(isset($_GET["index"])){
                $addUrl.="&index=".$_GET["index"]."&cid=".$_GET["itemid"];
            }else if(isset($_GET["cid"])){
               $addUrl.="&cid=".$_GET["cid"];
            }else  $addUrl.="&cid=".$_GET["itemid"];
            ?>
        <div>
            <a href="<?php echo $addUrl; ?>" class="add">Add page</a></div>
        <form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="frmcontentUpdate" id="frmcontentUpdate">
            <table width="100%" border="0" cellspacing="0" cellpadding="4">
                <tr>
                    <td width="50%" valign="top">
                        <table width="99%" align="center">
                            <tr valign="baseline">
                                <td width="25%">Page ID :</td>
                                <td width="75%"><strong><?php echo $row_rs_up['content_id']; ?></strong></td>
                            </tr>
                            <tr valign="baseline">
                                <td>Keywords:</td>
                                <td><input type="text" name="keywords" value="<?php echo htmlentities($row_rs_up['tags'], ENT_COMPAT, ''); ?>" size="32" /></td>
                            </tr>
                            <tr valign="baseline">
                                <td>
                                    Page title:</td>
                                <td><input type="text" name="ptitle" value="<?php echo htmlentities($row_rs_up['page_title'], ENT_COMPAT, ''); ?>" size="32" /></td>
                            <tr valign="baseline">
                                <td nowrap="nowrap" align="right">Direct link</td>
                                <td>
                                    <input type="checkbox" name="isDirect" id="isDirect" onclick="if(this.checked) showdiv('directlink')
                                       else hide('directlink');"  <?php $t="none";
                                           if(strlen($row_rs_up['direct_link'])>10) {
                                               $t="block";
                                               echo "checked='checked'";
                                           } ?>/>{Link page directly to another page}<div>
                                        <input name="directlink" type="text" id="directlink" value="<?php echo  $row_rs_up['direct_link']?>" class="<?php echo $t; ?>" />
                                </td>
                            </tr>

                            <tr valign="baseline">
                                <td colspan="2">Page text:</td>
                            </tr>

                            <tr valign="baseline">
                                <td colspan="2"><textarea name="pcontent"  id="textarea2"><?php echo htmlentities($row_rs_up['page_content'], ENT_COMPAT, ''); ?></textarea><script language="javascript1.2">
                                    generate_wysiwyg('textarea2');
                                    </script></td>
                            </tr>
                            <tr valign="baseline">
                                <td>Page Banner:</td>
                                <td><?php
                                    $rs_resources1 =getSiteBanners();
                                    $row_rs_resources1 = mysql_fetch_assoc($rs_resources1);
                                    $totalRows_rs_resources1 = mysql_num_rows($rs_resources1);

                                    ?>

                                    <?php do { ?>

                                    <input type="radio" name="pbanner" value="<?php echo  $row_rs_resources1["resource_id"]; ?>" id="grp_<?php echo  $row_rs_resources1["resource_id"]; ?>" <?php if($row_rs_resources1["resource_id"] ==$row_rs_up['page_banner']) echo "checked='checked'";?>  />
                                    <a href="../resources/<?php echo $row_rs_resources1['resource_url']; ?>" rel="facebox" >
                                        <img name="" src="../resources/thump.php?im=<?php echo  $row_rs_resources1["resource_url"]; ?>" alt="" /></a>
                                        <?php }while($row_rs_resources1 = mysql_fetch_assoc($rs_resources1));?>
                                    <input type="radio" name="pbanner" value="" />None
                                </td>
                            </tr>
                            <tr valign="baseline">
                                <td>Show Page:</td>
                                <td><select name="ispublished">
                                        <option value="yes" <?php if ($row_rs_up['is_published']==$YES_OPTION) {
                                            echo "SELECTED";
                                                } ?>>Yes</option>
                                        <option value="no" <?php if ($row_rs_up['is_published']==$NO_OPTION) {
                                            echo "SELECTED";
                                                } ?>>No</option>
                                    </select>
                                    <?php echo $row_rs_up['is_published'];?>
                                </td>
                            </tr>
                            <tr valign="baseline">
                                <td>Parent Category:</td>
                                <td>
                                    <?php
                                    $cat = $row_rs_up['category_id'];
                                    
                                    $rsrow = mysql_fetch_assoc(loadRelatedContentParent($cat,$row_rs_up['category_type'])); ?>
                                    <select id="categoryid" name="categoryid">
                                        <option value="0">None</option>
                                        <option value="<?php echo $rsrow["id"];?>" <?php if ($cat==$rsrow["id"]) echo "selected='selected'"; ?>><?php echo $rsrow["title"]?></option>
                                    </select></td>
                            </tr>
                            <tr valign="baseline">
                                <td>Source</td>
                                <td><input type="text" name="source" value="<?php echo htmlentities($row_rs_up['source'], ENT_COMPAT, ''); ?>" size="32" /></td>
                            </tr>
                            <?php $r=getListType($cat);
                            $rr=mysql_fetch_assoc($r);
							
                            if($rr["list_type"]>1 && $rr["list_type"]<5 ) { ?>
                            <tr valign="baseline">
                                <td> <?php
                                        if($rr["list_type"]==3)
                                            echo "Starts On";
                                        else
                                            echo "Date Created:";

                                        ?></td>
                                <td>
                                    <script type="text/javascript">
                                        var BASE='../';
                                        var cdate ="<?php echo substr($row_rs_up['date_created'],0,10); ?>";
                                        var yr = String( <?php echo ((int)date("Y"))?>);
                                        var d = String(<?php echo (date("d"));?>);
                                        var m= <?php echo ((date("m"))+1);?>;
                                    DateInput('datecreated', true, 'YYYY-MM-DD',cdate)</script>
                                        <?php ?>
                                    <select name="tstartH" class="small">
                                            <?php  $h = substr($row_rs_up['date_created'],11);
                                            $m = substr($row_rs_up['date_created'],14);
                                            echo createComboList(24,$h);
                                            ?>
                                    </select> Hr
                                    <select name="tstartM"  class="small">
                                            <?php
                                            echo createComboList(60,$m);
                                            ?>
                                    </select>Min
                                    (Time eg 18:00)</td>
                            </tr>
                            <tr valign="baseline">
                                <td><?php
                                        if($rr["list_type"]==3)
                                            echo "Ends On";
                                        else
                                            echo "Last modified:";

                                        ?>: </td>
                                <td>
                                    <script>
                                        var BASE='../';
                                        var cdate ="<?php echo substr($row_rs_up['last_modified'],0,10); ?>"
                                        var yr = String( <?php echo ((int)date("Y"))?>);var d = String(<?php echo (date("d"));?>);var m= String(<?php echo (date("m"));?>);
                                        DateInput('lastmodified', true, 'YYYY-MM-DD',cdate)</script>
                                    <select name="tendH" class="small">
                                            <?php  $h = substr($row_rs_up['last_modified'],11);
                                            $m = substr($row_rs_up['last_modified'],14);
                                            echo createComboList(24,$h);
                                            ?>
                                    </select> Hr
                                    <select name="tendM"  class="small">
                                            <?php
                                            echo createComboList(60,$m);
                                            ?>
                                    </select>Min
                                    (Time eg 18:00)</td>
                            </tr>
                                <?php } ?>
                            <tr valign="baseline">
                                <td colspan="2">&nbsp;</td>
                            </tr>
                            <tr valign="baseline">
                                <td colspan="2"></td>
                            </tr>
                            <tr valign="baseline">
                                <td colspan="2"><input type="submit" value="Update record" /></td>
                            </tr>
                            <tr valign="baseline">
                                <td colspan="2">&nbsp;</td>
                            </tr>
                        </table>
                        <input name="listtype" type="hidden" value="<?php echo $rr["list_type"]; ?>" />
                        <input type="hidden" name="MM_update" value="frmcontentUpdate" />
                        <input type="hidden" name="contentid" value="<?php echo $row_rs_up['content_id']; ?>" />

                    </td>

                    <td width="50%" valign="top">
                        <ul id="resourceRelated" class="shadetabs">
                            <li><a href="#" rel="tcontent5" class="selected">Resources </a></li>
                            <li><a href="#" rel="tcontent6">Related Pages</a></li>
                            <li><a href="#" rel="tcontentsubpage" class="selected">Sub Pages </a></li>
                            <li><a href="#" rel="tcontentcomment">Page Comments</a></li>
                        </ul>
                        <div class="allround">
                            <div id="tcontent5" class="tabcontent" style="padding:5px">
                                <?php if($totalRows_rs_resources>0) { ?>
                                No of Resources <strong class="redtxt"><?php echo $totalRows_rs_resources; ?></strong>
                                <div id="res_action"></div>
                                <div class="data_list">
                                    <table width="99%" border="0" cellpadding="5" cellspacing="0" id="datatable">
                                        <tr>
                                            <th>category</th>
                                            <th>Description</th>
                                            <th>Click</th>
                                            <th>Pos</th>
                                        </tr>
                                            <?php do {  ?>
                                        <tr>
                                            <td> <?php if($row_rs_resources['category_name']=="Images") {
                                                            ?>
                                                <a href="../resources/<?php echo $row_rs_resources['resource_url']; ?>" rel="facebox" ><img name="" src="../resources/thump.php?im=<?php echo $row_rs_resources['resource_url']; ?>"  alt="" /></a>
                                                            <?php }echo



        $row_rs_resources['category_name']; ?></td>
                                            <td><a href="pages/resource_edit.php?aj&itemid=<?php echo $row_rs_resources['resource_id']; ?>" rel="facebox" title="Edit : <?php echo $row_rs_resources['resource_description']; ?>"><?php echo $row_rs_resources['resource_description']; ?> [edit]</a></td>
                                            <td>
                                                <input type="button" name="button" id="del<?php echo $row_rs_resources['resource_id']; ?>" value="del" onclick="processResourceDeleteClick('del<?php echo $row_rs_resources['resource_id']; ?>',<?php echo $row_rs_resources['resource_id']; ?>,<?php echo $row_rs_up['content_id']; ?>,'d','res_action');" />
                                            </td>
                                            <td>
                                                <input name="resoursepos<?php echo $row_rs_resources['resource_id']; ?>" type="text" id="rpos<?php echo $row_rs_resources['resource_id']; ?>" onclick="" value="<?php echo $row_rs_resources['resource_order']; ?>" size="3" />
                                            </td>
                                        </tr>
        <?php } while ($row_rs_resources = mysql_fetch_assoc($rs_resources)); ?>
                                    </table>
                                </div>
                                    <?php }else {
                                    ?><span class="redtxt">No Resource Found</span><?php
}?><div id="data_list"><?php $radioBtnName=""; $checked="";include("images.php"); ?></div>
                            </div>
                            <div id="tcontent6" class="tabcontent">

<?php include("relatedpages.php"); ?>
                                <div id="relpage">
                                    <div class="action" style="border-top:solid 1px #CCC">Related Page</div>
                                    <input type="text" name="textfield" id="textfield" onkeyup="getData('pages/searchrelatedpage.php?aj&rel='+this.value,'srelatedpage');" />(Please type the page title of related page)
                                    <div id="srelatedpage"></div>
                                </div>
                            </div>
                            <div id="tcontentcomment" class="tabcontent">
                                <div id="relpage">
<?php include('page_comments.php'); ?>
                                </div>
                            </div>
                            <div id="tcontentsubpage" class="tabcontent">
                                <div id="relpage">
<?php include('subpages.php'); ?>
                                </div>
                            </div>

                        </div>
                    </td>
                </tr>
            </table>

        </form>

<?php if($row_rs_up["category_type"]=="cat") { ?>
    </div>
    <div class="tabcontent" id="tabcategory">
    <?php include 'category_update.php'; ?>
    </div>

</div>

    <?php } ?>
<script type="text/javascript">

<?php if($row_rs_up["category_type"]=="cat") { ?>
    var myflowers=new ddtabcontent("contentCategory") //enter ID of Tab Container
    myflowers.setpersist(true) //toogle ptersistence of the tabs' state
    myflowers.setselectedClassTarget("link") //"link" or "linkparent"
    myflowers.init()

    <?php } ?>
    var mytab=new ddtabcontent("resourceRelated") //enter ID of Tab Container
    mytab.setpersist(true) //toogle ptersistence of the tabs' state
    mytab.setselectedClassTarget("link") //"link" or "linkparent"
    mytab.init()
</script>
<?php
mysql_free_result($rs_up);
mysql_free_result($rs_resources);
?>